package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.OmsOrderReturnReason;
import com.itheima.manager.OmsOrderReturnReasonManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
    /*
      退货原因
    */

@RestController
@CrossOrigin(origins = "*")
public class OmsOrderReturnReasonController {

    @Autowired
    OmsOrderReturnReasonManager omsOrderReturnReasonManager;

    //退货原因表分页查询
    @GetMapping("/returnReason/list")
    public R findByPage(int pageNum, int pageSize) {
        return omsOrderReturnReasonManager.findByPage(pageNum,pageSize);

    }

    //回显数据
    @GetMapping("/returnReason/{id}")
    public R getInfoById(@PathVariable Long id) {
        return R.success(omsOrderReturnReasonManager.getInfoById(id));
    }

    //修改退货原因
    @PostMapping("/returnReason/update/{id}")
    public R update(@PathVariable Long id, @RequestBody OmsOrderReturnReason omsOrderReturnReason) {
        omsOrderReturnReasonManager.updateById(omsOrderReturnReason);
        return R.success("");
    }

    //修改退货原因状态
    @PostMapping("/returnReason/update/status")
    public R updateStatus(Integer ids, Integer status) {
        omsOrderReturnReasonManager.updateStatus(ids, status);
        return R.success("");
    }

    //批量删除
    @PostMapping("/returnReason/delete")
    public R delete(@RequestParam List<Long> ids) {
        omsOrderReturnReasonManager.delete(ids);
        return R.success("");
    }

    //添加退货原因
    @PostMapping("/returnReason/create")
    public R save(@RequestBody OmsOrderReturnReason omsOrderReturnReason) {
        omsOrderReturnReason.setCreateTime(LocalDateTime.now());
        omsOrderReturnReasonManager.save(omsOrderReturnReason);
        return R.success("");
    }
}


